<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class PinkValidate extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'image' => 'required',
            'houses_name' => 'required',
            'group_desc' => 'required',
            'site_detail' => 'required',
            'car_number' => 'required',
            'gather_site' => 'required',
            'start_time' => 'required',
            'end_time' => 'required',
        ];
    }

    public function messages(){
        return [
            'image.required' => '房产类型必须',
            'houses_name.required' => '团购名称必须',
            'group_desc.required' => '团购简介必须',
            'site_detail.required' => '详细地址必须',
            'car_number.required' => '车牌号必须必须',
            'gather_site.required' => '集合地址必须',
            'start_time.required' => '开始时间必须',
            'end_time.required' => '结束时间必须',
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw (new HttpResponseException(response()->json([
            'status_code' => '500',
            'message' => '请求错误',
            'data' => $validator->errors()->first(),
        ],200)));
    }
}
